﻿
using Microsoft.Xna.Framework;
using System.Reflection;
namespace ZombieGame
{
    public abstract class Entity : Drawable
    {
        public bool Alive = true;
        public int ID;
        public float Health;

        public virtual void Kill()
        {
            Alive = false;
            Health = 0f;
            try
            {
                ZombieGame.Current.World.Entities.Remove(this);
            }
            catch
            {
            }
            Dispose();
        }

        public Entity() :
            base()
        {
            ID = -1;
            int lid = 0;
            for (int i = 0; i < ZombieGame.Current.World.Entities.Count; i++)
            {
                Entity e = ZombieGame.Current.World.Entities[i];
                if (e.ID - lid > 1)
                {
                    ID = lid + 1;
                    break;
                }
                lid = e.ID;
            }
            if (ID == -1)
                ID = lid + 1;
        }

        public override void Update(GameTime time)
        {
            if (Alive && Position.X < -500f || Position.Y < -500f || Position.X > ZombieGame.Current.World.Size.X + 500f || Position.Y > ZombieGame.Current.World.Size.Y + 500f || Health <= 0f)
                Kill();
            base.Update(time);
        }
    }
}
